package com.songlanyun.modules.comment.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.songlanyun.common.drive.RootEntity;
import com.songlanyun.common.enums.CommentConstant;
import com.songlanyun.common.utils.SensiUtil;
import com.songlanyun.modules.comment.service.OrderGoodsCommentReplyService;
import com.songlanyun.modules.rabbitmq.util.SpringContextUtil;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 订单商品评论
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-11-30 18:09:47
 */
@Data
@TableName("yxt_sale_order_goods_comment")
public class OrderGoodsComment extends RootEntity<Long, OrderGoodsComment> implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     *
     */
    @TableId
    private Long id;
    /**
     * 商品id
     */
    private Long goodsId;
    /**
     * 商品名称
     */
    @TableField(exist = false)
    private String title;
    /**
     * 评论类型
     * ‘general’ ： 0普通商品
     * ‘service’ ： 1服务商品
     * ‘service’ ： 2联盟商家订单
     */
    private CommentConstant.CommentType type;
    /**
     * 图片
     */
    private String img;
    /**
     * 评论内容
     */
    private String content;

    public void setContent(String content) {
        SensiUtil sensiUtil = (SensiUtil) SpringContextUtil.getBean("sensiUtil");
        this.content = sensiUtil.filter(content);

    }

    /**
     * 评论时间
     */
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;
    /**
     * 会员id
     */
    private Long userId;

    @TableField(exist = false)
    private String nickname;
    @TableField(exist = false)
    private String mobile;
    @TableField(exist = false)
    private String headPhoto;
    /**
     * 商家id
     */
    private Long shopId;
    /**
     * 订单评论级别
     */
    @TableField("`level`")
    private Integer level;
    /**
     * 订单id
     */
    private Long orderId;
    /**
     * 子订单id
     */
    private Long chlidOrderId;

    /**
     * 1显示
     */
    @TableField("`show`")
    private Boolean show;

    /**
     * 商家是否已回复
     */
    @TableField(exist = false)
    private Boolean isReply;

    @TableField(exist = false)
    private List<OrderGoodsCommentReply> replyList;


    public void loadIsReply() {
        Boolean isReply = false;
        OrderGoodsCommentReplyService service = (OrderGoodsCommentReplyService) SpringContextUtil.getBean("orderGoodsCommentReplyService");
        List<OrderGoodsCommentReply> list = service.getByCommentId(this.getId());
        if (list != null && list.size() > 0) {
            isReply = true;
        }
        this.isReply = isReply;
        this.replyList = list;

    }

    @Override
    public Long getIdentity() {
        return id;
    }
}
